home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / readline.lha / readline / keymaps.c < prev    next >
C/C++ Source or Header  |  1991-01-19  |  4KB  |  174 lines

  1. /* keymaps.c -- Functions and keymaps for the GNU Readline library. */
  2.  
  3. /* Copyright (C) 1988,1989 Free Software Foundation, Inc.
  4.  
  5.    This file is part of GNU Readline, a library for reading lines
  6.    of text with interactive input and history editing.
  7.  
  8.    Readline is free software; you can redistribute it and/or modify it
  9.    under the terms of the GNU General Public License as published by the
  10.    Free Software Foundation; either version 1, or (at your option) any
  11.    later version.
  12.  
  13.    Readline is distributed in the hope that it will be useful, but
  14.    WITHOUT ANY WARRANTY; without even the implied warranty of
  15.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.    General Public License for more details.
  17.  
  18.    You should have received a copy of the GNU General Public License
  19.    along with Readline; see the file COPYING.  If not, write to the Free
  20.    Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  21.  
  22. #include "keymaps.h"
  23. #include "emacs_keymap.c"
  24.  
  25. #ifdef VI_MODE
  26. #include "vi_keymap.c"
  27. #endif
  28.  
  29. /* Remove these declarations when we have a complete libgnu.a. */
  30. #define STATIC_MALLOC
  31. #ifndef STATIC_MALLOC
  32. extern char *xmalloc (), *xrealloc ();
  33. #else
  34. static char *xmalloc (), *xrealloc ();
  35. #endif
  36.  
  37. /* **************************************************************** */
  38. /*                                    */
  39. /*              Functions for manipulating Keymaps.        */
  40. /*                                    */
  41. /* **************************************************************** */
  42.  
  43.  
  44. /* Return a new, empty keymap.
  45.    Free it with free() when you are done. */
  46. Keymap
  47. rl_make_bare_keymap ()
  48. {
  49.   register int i;
  50.   Keymap keymap = (Keymap)xmalloc (128 * sizeof (KEYMAP_ENTRY));
  51.  
  52.   for (i = 0; i < 128; i++)
  53.     {
  54.       keymap[i].type = ISFUNC;
  55.       keymap[i].function = (Function *)NULL;
  56.     }
  57.  
  58.   for (i = 'A'; i < ('Z' + 1); i++)
  59.     {
  60.       keymap[i].type = ISFUNC;
  61.       keymap[i].function = rl_do_lowercase_version;
  62.     }
  63.  
  64.   return (keymap);
  65. }
  66.  
  67. /* Return a new keymap which is a copy of MAP. */
  68. Keymap
  69. rl_copy_keymap (map)
  70.      Keymap map;
  71. {
  72.   register int i;
  73.   Keymap temp = rl_make_bare_keymap ();
  74.  
  75.   for (i = 0; i < 128; i++)
  76.     {
  77.       temp[i].type = map[i].type;
  78.       temp[i].function = map[i].function;
  79.     }
  80.   return (temp);
  81. }
  82.  
  83. /* Return a new keymap with the printing characters bound to rl_insert,
  84.    the uppercase Meta characters bound to run their lowercase equivalents,
  85.    and the Meta digits bound to produce numeric arguments. */
  86. Keymap
  87. rl_make_keymap ()
  88. {
  89.   extern rl_insert (), rl_rubout (), rl_do_lowercase_version ();
  90.   extern rl_digit_argument ();
  91.   register int i;
  92.   Keymap newmap;
  93.  
  94.   newmap = rl_make_bare_keymap ();
  95.  
  96.   /* All printing characters are self-inserting. */
  97.   for (i = ' '; i < 126; i++)
  98.     newmap[i].function = rl_insert;
  99.  
  100.   newmap[TAB].function = rl_insert;
  101.   newmap[RUBOUT].function = rl_rubout;
  102.   newmap[CTRL('H')].function = rl_rubout;
  103.  
  104.   return (newmap);
  105. }
  106.  
  107. /* Free the storage associated with MAP. */
  108. rl_discard_keymap (map)
  109.      Keymap (map);
  110. {
  111.   int i;
  112.  
  113.   if (!map)
  114.     return;
  115.  
  116.   for (i = 0; i < 128; i++)
  117.     {
  118.       switch (map[i].type)
  119.     {
  120.     case ISFUNC:
  121.       break;
  122.  
  123.     case ISKMAP:
  124.       rl_discard_keymap ((Keymap)map[i].function);
  125.       break;
  126.  
  127.     case ISMACR:
  128.       free ((char *)map[i].function);
  129.       break;
  130.     }
  131.     }
  132. }
  133.  
  134. #ifdef STATIC_MALLOC
  135.  
  136. /* **************************************************************** */
  137. /*                                    */
  138. /*            xmalloc and xrealloc ()                     */
  139. /*                                    */
  140. /* **************************************************************** */
  141.  
  142. static void memory_error_and_abort ();
  143.  
  144. static char *
  145. xmalloc (bytes)
  146.      int bytes;
  147. {
  148.   char *temp = (char *)malloc (bytes);
  149.  
  150.   if (!temp)
  151.     memory_error_and_abort ();
  152.   return (temp);
  153. }
  154.  
  155. static char *
  156. xrealloc (pointer, bytes)
  157.      char *pointer;
  158.      int bytes;
  159. {
  160.   char *temp = (char *)realloc (pointer, bytes);
  161.  
  162.   if (!temp)
  163.     memory_error_and_abort ();
  164.   return (temp);
  165. }
  166.  
  167. static void
  168. memory_error_and_abort ()
  169. {
  170.   fprintf (stderr, "readline: Out of virtual memory!\n");
  171.   abort ();
  172. }
  173. #endif /* STATIC_MALLOC */
  174.